package com.kate.mall.promotion.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.common.utils.Query;

import com.kate.mall.promotion.dao.GrouponDao;
import com.kate.mall.promotion.entity.GrouponEntity;
import com.kate.mall.promotion.service.GrouponService;


@Service("grouponService")
public class GrouponServiceImpl extends ServiceImpl<GrouponDao, GrouponEntity> implements GrouponService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GrouponEntity> page = this.page(
                new Query<GrouponEntity>().getPage(params),
                generatorQueryWrapper(params)
        );
        return new PageUtils(page);
    }
    public QueryWrapper generatorQueryWrapper(Map<String, Object> params) {//is_hot=1
        QueryWrapper<GrouponEntity> queryWrapper = new QueryWrapper<>();
        if (params.containsKey("goods_id")) {
            //where is_hot=1
            queryWrapper.eq("goods_id", Integer.parseInt((String) params.get("goods_id")));
        }
        return queryWrapper;
    }

    @Override
    public GrouponEntity getRecord(Integer id) {

        return this.getOne(Wrappers.<GrouponEntity>lambdaQuery().
                eq(GrouponEntity::getId,id).
                eq(GrouponEntity::getPayed,true).
                eq(GrouponEntity::getDeleted,false));
    }

}